package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.SetmealDish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.coyote.Request;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 目标:
 *
 * @author YUE
 * @date 2024/6/8 17:38
 */
@RestController
@Slf4j
@Api(tags = "商家分类相关接口")
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /*
      类别新增分类
     */
    @PostMapping
    @ApiOperation("类别新增分类")
    public Result add(@RequestBody CategoryDTO categoryDTO) {
        log.info("新增分类:{}", categoryDTO);
        categoryService.add(categoryDTO);
        return Result.success();
    }

    /*
      分页查询
     */
    @GetMapping("/page")
    @ApiOperation("类别分页查询")
    public Result<PageResult> page(CategoryPageQueryDTO query) {
        PageResult pr = categoryService.page(query);
        return Result.success(pr);
    }

    /*
       根据id删除分类
     */
    @DeleteMapping
    @ApiOperation("删除类别")
    public Result deleteId(Long id) {
        categoryService.deleteId(id);
        return Result.success();
    }

    /*
      修改分类
     */
    @PutMapping
    @ApiOperation("修改类别")
    public Result update(@RequestBody CategoryDTO categoryDTO) {
        categoryService.update(categoryDTO);
        return Result.success();
    }

    /*
      启用禁用分类
     */
    @PostMapping("/status/{status}")
    @ApiOperation("类别启用禁用")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        categoryService.startOrStop(status, id);
        return Result.success();
    }

    /*
      根据类型查询分类
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> type(Integer type) {
        List<Category> category = categoryService.list(type);
        return Result.success(category);
    }

}